package LeetCode;

import java.util.Arrays;

public class LC_026_RemoveDuplicatesfromSortedArray {
    public static void main(String[] args) {
        int[] a = {1, 4, 4, 4, 5, 5, 5, 6, 7, 8, 9};
        int n = Solution.removeDuplicates(a);
        System.out.println(n);
    }

    static class Solution {
        static int removeDuplicates(int[] nums) {
            int len = nums.length;
            if (len == 0)
                return 0;
            int count = 1;
            for (int i = 1; i < len; i++) {
                if (nums[i] != nums[i - 1]) {
                    nums[count] = nums[i];
                    count++;
                }
            }
            System.out.println(Arrays.toString(nums));
            return count;
        }
    }
}
